package demoMod.invincibleOne.cards.invincible;

import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.defect.ChannelAction;
import com.megacrit.cardcrawl.actions.defect.IncreaseMaxOrbAction;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.orbs.AbstractOrb;
import com.megacrit.cardcrawl.orbs.Dark;
import com.megacrit.cardcrawl.orbs.Frost;
import com.megacrit.cardcrawl.orbs.Lightning;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.powers.FocusPower;
import demoMod.invincibleOne.InvincibleOneMod;

public class Program extends AbstractInvincibleCard {
    public static final String ID = InvincibleOneMod.makeID("Program");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/Program.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.BASIC;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = 1;

    public Program() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseMagicNumber = this.magicNumber = 4;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            this.rawDescription = cardStrings.UPGRADE_DESCRIPTION;
            this.initializeDescription();
            upgradeMagicNumber(2);
        };
    }


    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        int j = 0;
        for (AbstractPower pw : p.powers) {
            if (pw.type.equals(AbstractPower.PowerType.DEBUFF) && pw.getClass().getCanonicalName().contains("com.megacrit.cardcrawl.powers")) {
                j++;
            }
        }
        int n = this.magicNumber - j;
        if (n > 0) {
            addToBot(new ApplyPowerAction(p, p, new FocusPower(p, n), n));
        }
        addToBot(new ChannelAction(new Lightning()));
        addToBot(new ChannelAction(new Frost()));
        addToBot(new ChannelAction(new Dark()));
    }
}
